import {Action,Actor} from 'iflux2'
import {fromJS} from 'immutable';

export const defaultParam = {totalCount:0,pageNum:1,pageSize:10};
import {PaginationType} from './type';


export default class Pagination extends Actor {
    constructor(pages = {}) {
        super();
        this.defaultParam = Object.assign(defaultParam, pages);
    }

    defaultState() {
        return {
            pagination: this.defaultParam
        }
    }

    @Action(PaginationType.SET_PAGINATION_PARAM)
    setPaginationParam(state,param){
        return state.set('pagination',param);
    }

    @Action(PaginationType.CHANGE_PAGE_PARAM)
    changePageCode(state,pageParam){
        return state.update('pagination',pagination=>pagination.merge(pageParam))
    }

    @Action(PaginationType.RESET_PAGINATION_PARAM)
    resetPagination(state){
        return state.set('pagination',fromJS(defaultParam));
    }
}